﻿using System;
using System.Collections.Generic;
using System.Text;
using GD.ModelContest.Model;
using System.Collections;

namespace GD.ModelContest.DataAccess.Impl.IBatisNet
{
    public class NewsSqlMapDao : BaseSqlMapDao, INewsDao
    {
        #region INewsDao 成员

        public bool InsertNews(mc_news news)
        {
            object obj = ExecuteInsert("Insertmc_news", news);
            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool UpdateNews(mc_news news)
        {
            int ret = ExecuteUpdate("Updatemc_news", news);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool DeleteNews(int newsId)
        {
            int ret = ExecuteDelete("Deletemc_news", newsId);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public mc_news GetNewsById(int newsId)
        {
            return ExecuteQueryForObject<mc_news>("Selectmc_news", newsId);
        }

        public IList<mc_news> GetNewsCollection(int newsTypeId, int pageIndex, int pageSize, ref int count)
        {
            Hashtable ht = new Hashtable();
            ht["NewsTypeId"] = newsTypeId;

            count = ExecuteQueryForObject<int>("SelectNewsCollectionByNewsTypeIdCount", ht);
            return ExecuteQueryForList<mc_news>("SelectNewsCollectionByNewsTypeId", ht, (pageIndex - 1) * pageSize, pageSize);
        }

        public IList<mc_news> GetNewsCollection(int newsTypeId, int num)
        {
            Hashtable ht = new Hashtable();
            ht["NewsTypeId"] = newsTypeId;
            ht["Num"] = num;

            return ExecuteQueryForList<mc_news>("SelectNewsCollectionByNum", ht);
        }

        #endregion
    }
}
